package com.xgry.bpm.api.business.author.dao;

import com.xgry.bpm.api.business.author.entity.TBAuthor;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xgry.bpm.api.business.author.vo.TreeDataCheckVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 权限表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2020-07-15
 */
public interface TBAuthorDao extends BaseMapper<TBAuthor> {

    @Select("SELECT au.id      AS id,\n" +
            "       au.text    AS text,\n" +
            "       au.url     AS url,\n" +
            "       au.iconCls AS iconCls,\n" +
            "       au.pid     AS pid,\n" +
            "       (\n" +
            "           CASE WHEN au.id = (SELECT top 1 (t_b_author.gateways + t_b_author.modulars + t_b_author.menus +\n" +
            "                                           t_b_author.functions) AS id\n" +
            "                             FROM t_b_author\n" +
            "                             WHERE t_b_author.role_id = #{roleId})\n" +
            "                   THEN 'true'\n" +
            "               ELSE 'false'\n" +
            "               END\n" +
            "           )      AS checked\n" +
            "FROM v_allauthor au\n" +
            "WHERE 1 = 1\n" +
            "ORDER BY au.Sort ASC")
    List<TreeDataCheckVo> getAuthorTree(@Param("roleId") Integer roleId);
}
